package com.etc.dao.impl;

import com.etc.dao.StudentDao;
import com.etc.entity.Student;
import com.etc.util.DBUtil;
import com.etc.util.PageData;

public class StudentDaoImpl implements StudentDao {

	@Override
	public PageData<Student> getStudent(int page, int limit, String content) {
		String sql = "select * from Student where stuname like ?";
		PageData pd = DBUtil.getPage(sql, page, limit, Student.class, "%" + content + "%");
		return pd;
	}

	@Override
	public boolean delStudent(int stuid) {
		String sql = "delete from student where stuid = ?";
		return DBUtil.execute(sql, stuid) > 0;
	}

	@Override
	public boolean updateStudent(Student stu) {
		String sql = "update student set stuname = ?,stuage = ?,stusex = ?,status = ? where stuid = ?";
		return DBUtil.execute(sql, stu.getStuname(), stu.getStuage(), stu.getStusex(), stu.getStatus(),
				stu.getStuid()) > 0;
	}

	@Override
	public boolean addStudent(Student stu) {
		String sql = "insert into student(stuname,stuage) values(?,?)";
		return DBUtil.execute(sql, stu.getStuname(), stu.getStuage(), stu.getStusex(), stu.getStatus()) > 0;
	}

}
